package com.love.driver.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.love.common.log.annotation.Log;
import com.love.common.log.enums.BusinessType;
import com.love.common.security.annotation.RequiresPermissions;
import com.love.driver.domain.LoveDriverRating;
import com.love.driver.service.ILoveDriverRatingService;
import com.love.common.core.web.controller.BaseController;
import com.love.common.core.web.domain.AjaxResult;
import com.love.common.core.utils.poi.ExcelUtil;
import com.love.common.core.web.page.TableDataInfo;

/**
 * 代驾服务评价Controller
 * 
 * @author love
 * @date 2025-09-13
 */
@RestController
@RequestMapping("/rating")
public class LoveDriverRatingController extends BaseController
{
    @Autowired
    private ILoveDriverRatingService loveDriverRatingService;

    /**
     * 查询代驾服务评价列表
     */
    @RequiresPermissions("driver:rating:list")
    @GetMapping("/list")
    public TableDataInfo list(LoveDriverRating loveDriverRating)
    {
        startPage();
        List<LoveDriverRating> list = loveDriverRatingService.selectLoveDriverRatingList(loveDriverRating);
        return getDataTable(list);
    }

    /**
     * 导出代驾服务评价列表
     */
    @RequiresPermissions("driver:rating:export")
    @Log(title = "代驾服务评价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LoveDriverRating loveDriverRating)
    {
        List<LoveDriverRating> list = loveDriverRatingService.selectLoveDriverRatingList(loveDriverRating);
        ExcelUtil<LoveDriverRating> util = new ExcelUtil<LoveDriverRating>(LoveDriverRating.class);
        util.exportExcel(response, list, "代驾服务评价数据");
    }

    /**
     * 获取代驾服务评价详细信息
     */
    @RequiresPermissions("driver:rating:query")
    @GetMapping(value = "/{ratingId}")
    public AjaxResult getInfo(@PathVariable("ratingId") Integer ratingId)
    {
        return success(loveDriverRatingService.selectLoveDriverRatingByRatingId(ratingId));
    }

    /**
     * 新增代驾服务评价
     */
    @RequiresPermissions("driver:rating:add")
    @Log(title = "代驾服务评价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LoveDriverRating loveDriverRating)
    {
        return toAjax(loveDriverRatingService.insertLoveDriverRating(loveDriverRating));
    }

    /**
     * 修改代驾服务评价
     */
    @RequiresPermissions("driver:rating:edit")
    @Log(title = "代驾服务评价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LoveDriverRating loveDriverRating)
    {
        return toAjax(loveDriverRatingService.updateLoveDriverRating(loveDriverRating));
    }

    /**
     * 删除代驾服务评价
     */
    @RequiresPermissions("driver:rating:remove")
    @Log(title = "代驾服务评价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ratingIds}")
    public AjaxResult remove(@PathVariable Integer[] ratingIds)
    {
        return toAjax(loveDriverRatingService.deleteLoveDriverRatingByRatingIds(ratingIds));
    }

    /**
     * 获取代驾订单主详细信息
     */
    @PostMapping(value = "/userReviewOrder")
    public AjaxResult userReviewOrder(@RequestBody LoveDriverRating loveDriverRating)
    {
        return toAjax(loveDriverRatingService.insertLoveDriverRating(loveDriverRating));
    }

    /**
     * 判断是否评价过
     */
    @GetMapping(value = "/getReviewByOrderId/{orderId}")
    public TableDataInfo getReviewByOrderId(@PathVariable Long orderId)
    {
        LoveDriverRating loveDriverRating =  new LoveDriverRating();
        loveDriverRating.setOrderId(orderId);
        List<LoveDriverRating> list = loveDriverRatingService.selectLoveDriverRatingList(loveDriverRating);
        return getDataTable(list);
    }
}
